import * as Koa from 'koa';
import { useControllers } from 'koa-controllers';
import * as Nunjucks from 'nunjucks';
import * as KoaStaticCache from 'koa-static-cache';

const app = new Koa();



app.use(async (ctx, next) => {

  
  ctx.template = new Nunjucks.Environment(
    new Nunjucks.FileSystemLoader(process.cwd() + '/views/')
  )

  await next()
})

app.use(KoaStaticCache('./static', {
  gzip: true,
  prefix: '/public',
  //设置静态文件访问每次都从文件(硬盘) 中读取,有利于开发调试,不过在代码上线以后,可以设置成非动态读取,那么程序运行的时候就会主动的把静态文件内容预加载进内存,访问的时候,就直接从内存中读取,提高性能.
  dynamic: true
}))

useControllers(app, __dirname + '/controllers/**/*.js', {

  multipart: {
    dest: process.cwd() + '/static/uploads/avatar'
  }

})

app.listen(7777);